package com.mail.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.mapper.OmsOrderReturnReasonMapper;
import com.mail.model.db.OmsOrderReturnReason;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class OmsOrderReturnReasonApiImpl implements OmsOrderReturnReasonApi {

    @Autowired
    private OmsOrderReturnReasonMapper orderReturnReasonMapper;

    //分页查询退货原因
    public Page queryByPage(Integer pageNum, Integer pageSize) {
        Page page = new Page(pageNum, pageSize);
        QueryWrapper<OmsOrderReturnReason> qw = new QueryWrapper<>();
        qw.orderByDesc("sort", "create_time");
        return orderReturnReasonMapper.selectPage(page, qw);
    }

    //根据id，获取单个退货原因详情信息
    public OmsOrderReturnReason findById(Long id) {
        return orderReturnReasonMapper.selectById(id);
    }

    //修改退货原因
    public Integer updateReturnReason(OmsOrderReturnReason reason) {
        return orderReturnReasonMapper.updateById(reason);
    }

    //批量删除退货原因
    public Integer deleteByIds(List<Long> ids) {
        return orderReturnReasonMapper.deleteBatchIds(ids);
    }

    //添加退货原因
    public Integer save(OmsOrderReturnReason reason) {
        return orderReturnReasonMapper.insert(reason);
    }
}
